package com.lzm.back.controller;

import com.github.pagehelper.PageInfo;
import com.lzm.back.common.MyResult;
import com.lzm.back.entity.Event;
import com.lzm.back.service.EventService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//赛事信息
@RestController
@RequestMapping("/evertInformation")
public class EventController {

    @Resource
    private EventService service;

    @PostMapping("addEventInformation")
    public MyResult addEventInformation(@RequestBody Event event) {
        service.addEventInformation(event);
        return MyResult.success();
    }

    @DeleteMapping("/deleteEventInformation")
    public MyResult deleteEventInformation(@RequestBody Event event) {
        service.deleteEventInformation(event);
        return MyResult.success();
    }
    @DeleteMapping("/{id}")
    public MyResult deleteEventInformation(@PathVariable Long id) {
        service.deleteEventInformationById(id);
        return MyResult.success();
    }
    @DeleteMapping("/batch")
    public MyResult deleteEventInformationBaTch(@RequestBody List<Long> ids) {
        service.deleteEventInformationBaTch(ids);
        return MyResult.success();
    }

    @PutMapping("/updateEventInformation")
    public MyResult updateEventInformation(@RequestBody Event event) {
        service.updateEventInformation(event);
        return MyResult.success();

    }


    @GetMapping("/SelectPage")
    public MyResult SelectPage(Event event,
                               @RequestParam(required = false) String name,//赛事类别名
                               @RequestParam(required = false) String location,//赛事地点
                               @RequestParam(defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize
    ) {

        PageInfo<Event> eventPageInfo = service.selectPage(event, location, name, pageNum, pageSize);

        return MyResult.success(eventPageInfo);
    }


}
